import {
  doLogin,
  register as registerApi
} from '../../api/login'
const APPID = 'wx29ae8672e455fbd7'
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  wxLogin(){
    // 1. 调用wx.login 获取临时登录凭证 code 码
    wx.login({
      success: (res) => {
        console.log(res);
        let code = res.code
        // 2. ajax 携带 APPID APPsecret code
        // 获取用户唯一标识符
        doLogin({
          code,
          appid:APPID
        }).then(res2=>{
          console.log(res2);
          // 3. 将用户唯一标识符 token 保存在本地
          wx.setStorageSync('token', res2.data.id)
        })
      },
    })
  },
  register(){
    registerApi({
      appId:APPID,
      appSecret:'5dcb587045bafd92e811c214cfb3a373'
    })
    .then(res=>{
      console.log(res);
    })
  }
})